package com.appkubes.mall.admin.application.system.config.controller;


import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.base.BaseController;
import com.appkubes.mall.admin.application.system.config.entity.dto.ConfigDTO;
import com.appkubes.mall.admin.application.system.config.entity.vo.GetConfigVO;
import com.appkubes.mall.admin.application.system.config.entity.vo.GetLeafConfigVO;
import com.appkubes.mall.admin.application.system.config.service.ConfigGlobalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api("全局配置模块")
@RestController
@RequestMapping("/system/config/global")
public class ConfigGlobalController extends BaseController {

    @Resource
    ConfigGlobalService configGlobalService;


    @ApiOperation("添加根配置")
    @PostMapping("/addRoot")
    public Response addRoot() {
        return Response.success();
    }

    @ApiOperation("添加配置项")
    @PostMapping("/addConfig")
    public Response addConfig() {
        return Response.success();
    }

    @ApiOperation("获取配置头")
    @GetMapping("/getRootNode")
    public Response getRootNode(@Valid GetConfigVO getConfigVO, BindingResult bindingResult) {
        ConfigDTO configDTO = configGlobalService.getConfigGlobal(getConfigVO.getSystemCode());
        return Response.success(configDTO);
    }

    @ApiOperation("获取配置")
    @GetMapping("/getLeafNode")
    public Response getLeafNode(@Valid GetLeafConfigVO getLeafConfigVO, BindingResult bindingResult) {
        List<ConfigDTO> configDTOs = configGlobalService.getLeafConfigGlobal(getLeafConfigVO.getAppKey(), getLeafConfigVO.getTypeConfigCode());
        return Response.success(configDTOs);
    }

    @ApiOperation("删除配置")
    @PostMapping("/del")
    public  Response del() {
        return Response.success();
    }


}